<template>
    <el-dialog class="dialog" :destroy-on-close="true" title="续期" :visible.sync="isShow" :close-on-click-modal="false"
        @close="onDialogClose">
        <el-form ref="form" label-width="auto" class="form" :model="formData" :rules="rules">
            <el-form-item label="人员名称"  class="big-el big-select">
                <div class="box-row">
                    <el-select v-model="formData.member_type" :disabled="isEdit">
                        <el-option v-for="item in categoriesData" :key="item.value" :label="item.label"
                            :value="item.value"></el-option>
                    </el-select>
                    <el-input v-model="formData.member_info"  :disabled="isEdit"  ></el-input>
                </div>
            </el-form-item>

            <el-form-item label="原始有效期" prop="old_end_time">
                <el-date-picker v-model="formData.old_end_time" value-format="yyyy-MM-dd" :disabled="isEdit" ></el-date-picker>
            </el-form-item>
            <el-form-item label="新的有效期" prop="end_time">
                <el-date-picker v-model="formData.end_time" value-format="yyyy-MM-dd" placeholder="请选择有效期"
                    :pickerOptions="pickerOptions"></el-date-picker>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="onDialogClose">取消</el-button>
            <el-button type="primary" @click="onSubmit">确认</el-button>
        </div>
    </el-dialog>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { Action, State } from "vuex-class";
import { mixinDialogForm } from "@/mixin/dialog/Form";
import { mixinTime } from "@/mixin/Time";
import uxUpload from "@/components/input/upload/index.vue";
@Component({
    mixins: [mixinTime, mixinDialogForm],
    components: { uxUpload }
})
export default class LadderscripRenew extends Vue {

    // 续期
    @Action("equipmentLadderscrip/renew") itemEdit: any;
    // 获取全部
    @State((state) => state.sharing.cardCategories) categoriesData: any;
    // 表单数据
    formData: any = {
        end_time: "",
        member_type: "",
        member_info: '',
        old_end_time: ""
    };

    editInit(data: any) {
        const me = this as any;
        data.member_type = data.member_type.toString();
        data.old_end_time = data.end_time;
        data.member_info = data.member_xm + '(' + data.phone + ')';
        me.formData = Object.assign({}, me.formData, data);
    }
    /**
     * 校验配置
     *
     * @type {*}
     * @memberof mixinViewRules
     */
    rules: any = {
        end_time: [
            {
                required: true,
                message: "请选择有效期",
                trigger: "blur"
            }
        ]
    };
    pickerOptions: any = {
        shortcuts: [
            {
                text: '一个月',
                onClick(picker) {
                    const end = new Date();
                    end.setMonth(end.getMonth() + 1);
                    picker.$emit('pick', end);
                }
            },
            {
                text: '三个月',
                onClick(picker) {
                    const end = new Date();
                    end.setMonth(end.getMonth() + 3);
                    picker.$emit('pick', end);
                }
            },
            {
                text: '六个月',
                onClick(picker) {
                    const end = new Date();
                    end.setMonth(end.getMonth() + 6);
                    picker.$emit('pick', end);
                }
            },
            {
                text: '一年',
                onClick(picker) {
                    const end = new Date();
                    end.setMonth(end.getMonth() + 12);
                    picker.$emit('pick', end);
                }
            }
        ]
    };

}
</script>
